package com.fwx.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fwx.dao.DeptDao;
import com.fwx.entity.Dept;
import com.fwx.entity.Emp;
import com.fwx.service.DeptService;
import com.fwx.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: springBoot06
 * @description:
 * @author: 范文轩
 * @create: 2024-07-15 10:31
 **/

@Service
public class DeptServiceImpl implements DeptService {
    
    @Autowired
    private DeptDao deptDao;
    
    @Override
    public R insert(Dept dept) {
        int row = deptDao.insert(dept);
        if (row > 0){
            return new R(200,"添加成功",row);
        }
        return new R(500,"添加失败",null);
    }

    @Override
    public R updateById(Dept dept) {
        int row = deptDao.updateById(dept);
        if (row > 0){
            return new R(200,"修改成功",row);
        }
        return new R(500,"修改失败",null);
    }

    @Override
    public R deleteById(Integer deptno) {
        int row = deptDao.deleteById(deptno);
        if (row > 0){
            return new R(200,"删除成功",row);
        }
        return new R(500,"删除失败",null);
    }

    @Override
    public R selectAll(Integer current, Integer size) {
        Page<Dept> page = new Page<>(current,size);
        QueryWrapper<Dept> wrapper = new QueryWrapper<>();
        Page<Dept> empPage = deptDao.selectAll(page,wrapper);
        if (empPage.getSize() > 0){
            return new R(200,"查询成功",empPage.getRecords());
        }
        return new R(500,"很抱歉，没有找到相关信息",null);
    }

    @Override
    public R selectByDeptNo(Integer deptno) {
        Dept dept = deptDao.selectById(deptno);
        if (dept != null){
            return new R(200,"查询成功",dept);
        }
        return new R(500,"很抱歉，没有找到该部门",null);
    }
}
